import axios from './axios'
import qs from 'qs'

import {
    addStockOutApplication,
    stockOutApplicationDetail,
    getStockOutApplicationList,
    updateStockOutApplication,
    deleteApply,
    saveStockOut,
    stockOut,
    deleteStockOut,
    createStockNo,
    getStockOutDetail,
    getStockOutList,
    getStockWorkNo,
    getStockoutSelectList,
    getStockOutRecord,
    getStockOutNo,
    getStockOutApplicationListWithoutPage,
} from './stockOut'

import {
    stockIn, saveStockIn, getStockInDetail, getStockInList, getStockInRecord, getSupplier,getWarehouseStock
} from './stockIn'

import {
    addPay,
    addIdrInvoice,
    idrInvoiceDetail,
    idrInvoiceList,
    deleteAllInvoice,
    deleteInvoice,
    deleteServiceInvoice,
    deleteIdrInvoice,
    payDetail,
    getSumInvoiceDetail,
    createSumInvoice,
    createInvoice,
    serviceInvoiceDetail,
    getSumInvoiceList,
    getInvoiceRecipt,
    getInvoiceList,
    modifyInvoiceRecipt,
    modServiceInvoice,
    modIdrInvoice

} from './invoice'

export {
    addPay,
    addIdrInvoice,
    idrInvoiceDetail,
    idrInvoiceList,
    deleteAllInvoice,
    deleteInvoice,
    deleteServiceInvoice,
    deleteIdrInvoice,
    payDetail,
    getSumInvoiceDetail,
    createSumInvoice,
    createInvoice,
    serviceInvoiceDetail,
    getSumInvoiceList,
    getInvoiceRecipt,
    getInvoiceList,
    modifyInvoiceRecipt,
    modServiceInvoice,
    modIdrInvoice
}
export {
    addStockOutApplication,
    stockOutApplicationDetail,
    getStockOutApplicationList,
    updateStockOutApplication,
    deleteApply,
    saveStockOut,
    stockOut,
    deleteStockOut,
    createStockNo,
    getStockOutDetail,
    getStockOutList,
    getStockWorkNo,
    getStockoutSelectList,
    getStockOutRecord,
    getStockOutNo,
    getStockOutApplicationListWithoutPage
}

export {
    stockIn, saveStockIn, getStockInDetail, getStockInList, getStockInRecord, getSupplier,getWarehouseStock
}

export function getEmployeeList() {
    return axios.get('/employee/manage/all_employee.do').then(res => Promise.resolve(res.data))
}

export function getCustomerList() {
    return axios.get('/service/custom_list.do').then(res => Promise.resolve(res.data))
}

export function getRequestNo() {
    return axios.get('/manage/search/get_request_no.do').then(res => Promise.resolve(res.data))
}

//获取quest列表的initiator
export function getRequestBy() {
    return axios.get('/manage/working_order/show_request_by_list.do').then(res => Promise.resolve(res.data))
}

// 删除采购申请
export function deletePurchaseRequest(id) {
    return axios({
        url: '/iec_purchase/manage/delete_purchase_order.do',
        method: 'get',
        params: {id}
    }).then(res => Promise.resolve(res.data))
}

export function getQuestList({pageNum, pageSize = 100, requestNo, plateNum, typeCode, initiator}) {
    return axios.post('/manage/order/show_service.do', qs.stringify({
        pageNum,
        pageSize,
        requestNo,
        plateNum,
        typeCode,
        initiator
    })).then(res => Promise.resolve(res.data))
}

export function searchQuest(customerName, unitModel) {
    return axios.post('/manage/order/select_service.do', qs.stringify({
        customerName,
        unitModel
    })).then(res => Promise.resolve(res.data))
}

export function getPlateNo(customer) {
    return axios.post('/service/service_information_list.do?customer=' + customer).then(res => Promise.resolve(res.data))
}

export function getDeviceInfo({plateNum}) {
    return axios.post('/service/service_by_plate_num.do', qs.stringify({plateNum})).then(res => Promise.resolve(res.data))
}

export function subQuest({
                             requestNo, requestDate, initiator, customerId, customerName, addressId, address, distance, unitModel, sn,
                             deliveryTime, hmKm, typeCode, serviceType, appointmentTime, note, status, projectName, plateNum,
                             charges, problems, operator, requestName
                         }) {
    const data = qs.stringify({
        requestNo, requestDate, initiator, customerId, customerName, addressId, address, distance, unitModel, sn,
        deliveryTime, hmKm, typeCode, serviceType, appointmentTime, note, status, projectName, plateNum,
        charges, problems, operator, requestName
    });
    return axios.post('/manage/order/request_service.do', data).then(res => Promise.resolve(res.data))

}

export function modQuest({
                             requestNo, requestDate, initiator, customerId, customerName, addressId, address, distance, unitModel, sn,
                             deliveryTime, hmKm, typeCode, serviceType, appointmentTime, note, status, projectName, plateNum,
                             charges, problems, operator, id, requestName
                         }) {
    const data = qs.stringify({
        requestNo, requestDate, initiator, customerId, customerName, addressId, address, distance, unitModel, sn,
        deliveryTime, hmKm, typeCode, serviceType, appointmentTime, note, status, projectName, plateNum, operator, id,
        charges, problems, requestName
    });
    return axios.post('/manage/order/update_service.do', data).then(res => Promise.resolve(res.data))

}

export function showQuestDetail(id) {
    return axios.post('/manage/order/show_service_detail.do', qs.stringify({id})).then(res => Promise.resolve(res.data))
}

export function deleteQuest(id) {
    return axios.post('/manage/order/delete_service.do', qs.stringify({id})).then(res => Promise.resolve(res.data))
}

export function getWorkingOrder({pageSize = 100, pageNum, requestNo, typeCode, woStatus, startTime, endTime, workingNo}) {
    return axios.post('/manage/working_order/service_list_working_order.do',
        qs.stringify({
            pageSize,
            pageNum,
            requestNo,
            typeCode,
            startTime,
            endTime,
            woStatus,
            workingNo
        }))
        .then(res => Promise.resolve(res.data))
}

export function getWorkNo() {
    return axios.get('/manage/working_order/get_working_no.do').then(res => Promise.resolve(res.data))
}

export function getWorkDetail(workingId) {
    return axios.post('/manage/working_order/working_order_detail.do', qs.stringify({workingId})).then(res => Promise.resolve(res.data))
}

export function getRealParts(workOrderNo) {
    return axios.post('/manage/close_order/show_really_parts_num.do', qs.stringify({workOrderNo})).then(res => Promise.resolve(res.data))
}

export function getPart(workOrderNo) {
    return axios.post('/manage/working_order/select_spare_parts.do', qs.stringify({workOrderNo})).then(res => Promise.resolve(res.data))
}

export function saveWorkingOrder(work) {
    const data = qs.stringify(work);
    return axios.post('/manage/working_order/save_working_order.do', data).then(res => Promise.resolve(res.data))
}


export function getCloseUnit() {
    return axios.get('/service_charge/manage/select_unit.do').then(res => Promise.resolve(res.data))
}

export function getCloseCategory() {
    return axios.get('/service_charge/manage/select_category.do').then(res => Promise.resolve(res.data))
}

export function getCloseWorkCode({unit, category, pointCode}) {
    return axios.post('/service_charge/manage/select_service_charge_item.do', qs.stringify({
        unit,
        category,
        pointCode
    })).then(res => Promise.resolve(res.data))
}

export function getCloseList() {
    return axios.post('/manage/close_order/show_order_list_by_status.do', qs.stringify({pageSize: 1000})).then(res => Promise.resolve(res.data))
}

export function closeOrder({orderId, remarks, recommendation, problem, suggestion, depletes, endDate, handOver, unit, category, causeOfProblem, pointCode}) {
    const data = qs.stringify({
        orderId,
        remarks,
        recommendation,
        problem,
        suggestion,
        depletes,
        endDate,
        handOver,
        unit,
        category,
        causeOfProblem,
        pointCode
    });
    return axios.post('/manage/close_order/close_order.do', data).then(res => Promise.resolve(res.data))
}

export function getSimcStockIn() {
    return axios.get('/simulation_storage/manage/show_simulation_storage_list.do').then(res => Promise.resolve(res.data));
}


export function getReport(condition) {
    return axios.post('/statistical_report/select_statistical_report.do', qs.stringify(condition)).then(res => Promise.resolve(res.data))
}

export function getProject() {
    return axios.get('/project/show_project.do').then(res => Promise.resolve(res.data))
}

export function getEquipment() {
    return axios.get('/service/equipment_list.do').then(res => Promise.resolve(res.data))
}

export function modEquipment({serviceNum, arrieveDateStr, contract, equipmentType, brand, sn, engine, engineType, model, belongCompany, plateNum, project, id}) {
    const data = qs.stringify({
        serviceNum,
        arrieveDateStr,
        contract,
        equipmentType,
        brand,
        sn,
        engine,
        engineType,
        model,
        belongCompany,
        plateNum,
        project,
        id
    });
    return axios.post('/service/modify_equipment.do', data).then(res => Promise.resolve(res.data))
}

export function addEquipment({serviceNum, arrieveDateStr, contract, equipmentType, brand, sn, engine, engineType, model, belongCompany, plateNum, project}) {
    const data = qs.stringify({
        serviceNum,
        arrieveDateStr,
        contract,
        equipmentType,
        brand,
        sn,
        engine,
        engineType,
        model,
        belongCompany,
        plateNum,
        project
    });
    return axios.post('/service/add_equipment.do', data).then(res => Promise.resolve(res.data))

}

export function deleteEquipment(id) {
    const data = qs.stringify({id});
    return axios.post('/service/delete_equipment.do', data).then(res => Promise.resolve(res.data))
}

export function deleteProject(id) {
    const data = qs.stringify({id});
    return axios.post('/project/delete_project.do', data).then(res => Promise.resolve(res.data))
}

export function addProject({plateNum, longitude, latitude, projectName, startTimeStr, endTimeStr}) {
    const data = qs.stringify({plateNum, longitude, latitude, projectName, startTimeStr, endTimeStr});
    return axios.post('/project/add_project.do', data).then(res => Promise.resolve(res.data))
}

export function modProject({plateNum, longitude, latitude, projectName, startTimeStr, endTimeStr, id}) {
    const data = qs.stringify({plateNum, longitude, latitude, projectName, startTimeStr, endTimeStr, id});
    return axios.post('/project/modify_project.do', data).then(res => Promise.resolve(res.data))
}

export function getOrder(workingNo) {
    return axios.post('/manage/working_order/report_detail.do', qs.stringify({workingNo})).then(res => Promise.resolve(res.data))
}

export function getAllReport() {
    return axios.post('/history_order/select_by_num_time.do').then(res => Promise.resolve(res.data))
}

export function getTopTen(startTime, endTime) {
    return axios.post('/history_order/select_top_plate_num.do', qs.stringify({
        startTime,
        endTime
    })).then(res => Promise.resolve(res.data))
}

export function getPointList() {
    return axios.get('/service_charge/manage/show_service_charge_list.do').then(res => Promise.resolve(res.data))
}

//不再能手动添加
export function addPoint(point) {
    return axios.post('/iec_service/manage/add_item.do', qs.stringify(point)).then(res => Promise.resolve(res.data))
}

export function modPoint(point) {
    return axios.post('/iec_service/manage/update_item.do', qs.stringify(point)).then(res => Promise.resolve(res.data))
}


export function getCostList() {
    return axios.get('/spare_cost/manage/get_all_list.do').then(res => Promise.resolve(res.data))
}

export function addCost(cost) {
    return axios.post('/spare_cost/manage/add_spare_cost.do', qs.stringify(cost)).then(res => Promise.resolve(res.data))
}


//  获取联系人电话
export function customerContactPhone(contactId) {
    return axios.post('/contact/manage/select_customer_contact_phone.do', qs.stringify({contactId})).then(res => Promise.resolve(res.data))
}

export function getCustomerAddress(customerId) {
    return axios.post('/address/manage/get_customer_address.do', qs.stringify({customerId})).then(res => Promise.resolve(res.data))
}

export function getCustomerContact(customerId) {
    return axios.post('/contact/manage/get_customer_contact.do', qs.stringify({customerId})).then(res => Promise.resolve(res.data))
}

export function getContactByCustomer(customerName) {
    return axios.post('/contact/manage/get_customer_contact_by_name.do', qs.stringify({customerName})).then(res => Promise.resolve(res.data))
}

export function getAllExportInfo() {
    return axios.get('/spare_parts_export/manage/show_all_export.do').then(res => Promise.resolve(res.data))
}

export function deleteStockIn(stockInId) {
    return axios.post('/optimization_inventory/manage/delete_stock_in_record.do', qs.stringify({stockInId})).then(res => Promise.resolve(res.data))
}


//  船
export function showAllExport() {
    return axios.get('/spare_parts_export/manage/show_all_export.do').then(res => Promise.resolve(res.data))
}

//获取warehouse2 3的库存
export function showStock23(info) {
    return axios.post('/optimization_inventory/manage/select_one_and_three_stock.do', qs.stringify(info)).then(res => Promise.resolve(res.data))
}

//获取船信息
export function getAllShipInfo() {
    return axios.get('/stock_change_record/show_ship_information.do').then(({data}) => Promise.resolve(data))
}

//新的point code列表
export function getPcList() {
    return axios.get('/iec_service/manage/show_item_list.do').then(({data}) => Promise.resolve(data))
}

//新的point code category
export function getPcCategoryList() {
    return axios.get('/iec_service/manage/show_category_list.do').then(({data}) => Promise.resolve(data))
}

//新的point code unit
export function getPcUnit() {
    return axios.get('/iec_service/manage/show_unit_list.do').then(({data}) => Promise.resolve(data))
}

//职位列表
export function getPositionList() {
    return axios.get('/employee/manage/show_position_level_list.do').then(res => Promise.resolve(res.data))
}

//职位添加等级
export function addPositionLevel(position) {
    return axios.post('/employee/manage/add_position_level.do', qs.stringify(position)).then(res => Promise.resolve(res.data))
}

//更新职位
export function updatePositionLevel(position) {
    return axios.post('/employee/manage/update_position_level.do', qs.stringify(position)).then(res => Promise.resolve(res.data))
}

export function deletePosition(id) {
    return axios.get(`/employee/manage/delete_position_level.do?id=${id}`).then(res => Promise.resolve(res.data))
}

//查看员工的内容
export function getEmployeeWork(id, month) {
    let url;
    if (month) {
        url = `/employee/manage/show_working_detail.do?id=${id}&month=${month}`
    } else {
        url = `/employee/manage/show_working_detail.do?id=${id}`
    }
    return axios.get(url).then(res => Promise.resolve(res.data))

}

//员工工作排行榜
export function employeeWorkBoard(date) {
    return axios.post('/employee/manage/show_staff_leader_board.do', qs.stringify(date))
        .then(res => Promise.resolve(res.data))
}

//回撤Wo
export function woGoBack(id) {
    return axios.get(`/manage/working_order/revoke_close_order.do?id=${id}`).then(res => Promise.resolve(res.data))
}

//上传excel po
export function uploadPurchaseExcel(formData) {
    return axios.post('/iec_purchase/manage/excel_iec_purchase', formData, {
        headers: {'Content-Type': 'multipart/form-data'}
    }).then(res => Promise.resolve(res.data))
}

//上传主机excel
export function uploadEquipment(formData) {
    return axios.post('/service/excel_equipment_sold', formData, {
        headers: {'Content-Type': 'multipart/form-data'}
    }).then(res => Promise.resolve(res.data))
}

//po list
export function getPoList(status) {
    return axios.post('/iec_purchase/manage/show_purchase_list.do', qs.stringify({status})).then(res => Promise.resolve(res.data))
}

//po detail
export function getPoDetail(id) {
    return axios.get(`/iec_purchase/manage/show_purchase_detail.do?id=${id}`).then(res => Promise.resolve(res.data))
}

//add po
export function addPo(Po) {
    return axios.post('/iec_purchase/manage/add_iec_purchase.do', qs.stringify(Po)).then(res => Promise.resolve(res.data))
}

//update po
export function updatePo(Po) {
    return axios.post('/iec_purchase/manage/update_iec_purchase.do', qs.stringify(Po)).then(res => Promise.resolve(res.data))
}

//3号仓库价格
export function getSpPriceW3() {
    return axios.get('/iec_purchase/manage/show_warehouse_spare_parts_price_list.do').then(res => Promise.resolve(res.data))
}

//3好仓库价格变动
export function getPriceChange(partsId) {
    return axios.get(`/iec_purchase/manage/show_warehouse_history_price.do?partsId=${partsId}`).then(res => Promise.resolve(res.data))
}

//working order 统计
export function wokingOrderInvoice(condition) {
    return axios.post('/manage/working_order/statistics_close_order.do', qs.stringify(condition))
        .then(res => Promise.resolve(res.data))
}


// 购买设备公司列表：/service/custom_list.do
export function getEquipmentCustomerList() {
    return axios.get('/service/custom_list.do').then(res => Promise.resolve(res.data))
}

// 公司下属设备：/service/equipment_list.do  参数：customer(名称)
export function getEquipmentByCustomer(customer) {
    return axios.get(`/service/equipment_list.do?customer=${customer}`).then(res => Promise.resolve(res.data))
}

//
// 设备工作单：/manage/working_order/show_work_order_list_by_plate_num.do  参数：plateNum
export function getWoByEquipment(plateNum) {
    return axios.get(`/manage/working_order/show_work_order_list_by_plate_num.do?plateNum=${plateNum}`)
        .then(res => Promise.resolve(res.data))
}

//tid 油量
export function oilList() {
    return axios.get('/tid_fuel_consumption_record/manage/show_all_record.do').then(res => Promise.resolve(res.data))
}

export function addOil(oil) {
    return axios.post('/tid_fuel_consumption_record/manage/add_fuel_consumption_record.do', qs.stringify(oil))
        .then(res => Promise.resolve(res.data))
}

export function modOil(oil) {
    return axios.post('/tid_fuel_consumption_record/manage/update_fuel_consumption_record.do', qs.stringify(oil))
        .then(res => Promise.resolve(res.data))
}

export function oilChart(condition) {
    return axios.post('/fuel_consumption_chart/manage/fuel_consumption_chart.do', qs.stringify(condition))
        .then(res => Promise.resolve(res.data))
}

export function oilExcel(formData) {
    return axios.post('/tid_fuel_consumption_record/manage/excel_fuel_consumption.do', formData, {
        headers: {'Content-Type': 'multipart/form-data'}
    }).then(res => Promise.resolve(res.data))
}

export function deletePointCode(id) {
    return axios.get(`/iec_service/manage/delete_item.do?id=${id}`).then(res => Promise.resolve(res.data))
}


export function getShipInfoById(id) {
    return axios.get('/spare_parts_export/manage/show_spare_parts_by_ship.do?id=' + id).then(res => Promise.resolve(res.data))
}

// 日报
export function getPartReport(belongModule,warehouse) {
    return axios.get(`/statistic_chart/manage/in_stock_price_for_current_month.do`,{
        params:{
            belongModule,
            warehouse
        }
    }).then(res => Promise.resolve(res.data))
}
/*=========================================>.<+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
